﻿@*@model IEnumerable<SealManagement.Models.User>*@
@{
    ViewData["Titel"] = "Index";
}

<script src="~/lib/jquery/jquery-1.12.4.js"></script>
<script src="~/lib/jquery/jquery-1.12.4.min.js"></script>
<script>

    $(function () {
        $('.Del').click(function () {
            //var Id = $('#hidden').val();
            var Id = $(this).attr('data');
            //var url = $(this).attr('href');
            //var params = {
            //    id: Id
            //};
            if (confirm("是否确认删除？")) {
                $.ajax({
                    url: "/User/Delete/" + Id,
                    //url: url,
                    type: 'Get',
                    //contentType: 'application/json',
                    //dataType: 'JSON',
                    //data: JSON.stringify(params),
                    success: function (data) {
                        if (data != null && data.state == '200') {
                            alert(data.message);
                            window.location.href = '/User/Index';
                        } else {
                            alert(data.message);
                        }
                    }
                });
            }
        });
    })
</script>

<table class="table table table-hover">
    <thead>
        <tr>
            <th class="text-center">
                姓名
            </th>
            <th class="text-center">
                电话
            </th>
            <th class="text-center">
                邮箱
            </th>
            <th class="text-center">
                操作
            </th>
        </tr>
    </thead>
    <tbody id="userList"></tbody>
</table>
<div class="row ">
    <div id="Page" class="col-md-6 col-md-offset-3 "></div>
</div>

<script>
    $(function () {
        var total;
        console.log(total);
        function getUserList(PageSize, PageIndex) {
            $.ajax({
                url: "/User/Index",
                type: 'POST',
                data: { PageSize, PageIndex },
                success: function (result) {
                    total = result.total;
                    console.log(total);
                    var Items = result.data;
                    var _html = '';
                    $.each(Items, function (i) {
                        var Item = Items[i];
                        _html += ' <tr class="text-center">';
                        _html += '<td>' + Item.userName + '</td >';
                        _html += '<td>' + Item.phoneNumber + '</td >';
                        _html += '<td>' + Item.email + '</td >';
                        _html += '<td>';
                        _html += '<a class="btn btn-sm btn-black" href="/User/Detail/' + Item.id + '" >查看</a> '
                        _html += '<a class="btn btn-sm btn-black" href="/User/Edit/' + Item.id + '" >编辑</a> '
                        _html += '<a class="Del btn btn-sm btn-danger" href="javascript:void(0)" data=' + Item.id + '>删除</a>'
                        _html += '</td>';
                        _html += '</tr>';
                    })
                    $("#userList").html(_html);
                }
            });
        }
        layui.use(['laypage', 'layer'], function () {
            var laypage = layui.laypage
                , layer = layui.layer;
            laypage.render({
                elem: 'Page'
                , count: total //数据总数，从服务端得到
                , limit: 10
                , theme: '#393D49'
                , jump: function (obj, first) {
                    //obj包含了当前分页的所有参数，比如：
                    console.log(obj.curr); //得到当前页，以便向服务端请求对应页的数据。
                    console.log(obj.limit); //得到每页显示的条数

                    //首次不执行
                    if (!first) {
                        getUserList(10, obj.curr)
                    } else {
                        getUserList(10, 1)
                    }
                }
            });
        });
    })

</script>